package math

import (
	"go_learn/actor"
	"math"
)

type Math struct {
	actor.ConcurrentActor
}

func (slf *Math) Name() string {
	return "math"
}

func (slf *Math) OnInit() {
	slf.RegistHandle(actor.Normal, "square", slf.square)
	slf.RegistHandle(actor.Normal, "cbrt", slf.cbrt)
	slf.RegistHandle(actor.Normal, "multiply", slf.multiply)
	slf.RegistHandle(actor.Normal, "divide", slf.divide)
	slf.RegistHandle(actor.Normal, "add", slf.add)
	slf.RegistHandle(actor.Normal, "dec", slf.dec)
}

func (slf *Math) Run(args interface{}) {
}

func (slf *Math) OnDestroy() {

}

func (slf *Math) square(source uint, n float64) (ret interface{}, err error) {
	ret = math.Sqrt(n)
	return
}

func (slf *Math) cbrt(source uint, n float64) (ret interface{}, err error) {
	ret = math.Cbrt(n)
	return
}

func (slf *Math) multiply(source uint, x float64, y float64) (ret interface{}, err error) {
	ret = x * y
	return
}

func (slf *Math) divide(source uint, x float64, y float64) (ret interface{}, err error) {
	ret = x / y
	return
}

func (slf *Math) add(source uint, x float64, y float64) (ret interface{}, err error) {
	ret = x + y
	return
}

func (slf *Math) dec(source uint, x float64, y float64) (ret interface{}, err error) {
	ret = x - y
	return
}
